package com.pan.structual.bridge;

import com.pan.structual.bridge.color.MyColor;
import com.pan.structual.bridge.color.impl.Blue;
import com.pan.structual.bridge.color.impl.Green;
import com.pan.structual.bridge.color.impl.Red;
import com.pan.structual.bridge.graphics.Shape;
import com.pan.structual.bridge.graphics.impl.Circle;
import com.pan.structual.bridge.graphics.impl.Rectangle;
import com.pan.structual.bridge.graphics.impl.Square;
import com.pan.structual.bridge.utils.DrawPicture;

import java.awt.image.BufferedImage;
import java.util.Arrays;

/**
 * 桥接模式
 * 把一个事物的多个维度拆分出来，方便扩展、降低复杂性
 *
 * shape    color
 *
 * circle   red
 * square   blue
 * rectangle    green
 * 如果耦合在一起，将变得很复杂，如添加一种颜色要为各个图像再建立一个类
 *
 * 如果用桥接模式拆开各个维度，比如加一个颜色Yellow，就加对应的颜色维度就行了,
 * 如果传统的各个维度耦合在一起的话，就要为各个图形再添加一个类，YellowCircle、YellowSquare、YellowRectangle……
 *
 *
 */
public class BridgeApplication {

    public static void main(String[] args) {
        MyColor[] myColors = {new Red(), new Green(),new Blue()};
        Shape[] shapes = {new Circle(),new Rectangle(),new Square()};


        for (int i = 0; i < shapes.length; i++) {
            Shape shape =  shapes[i];
            for (int j = 0; j < shapes.length; j++) {
                shape.setMyColor(myColors[j]);
                BufferedImage picture = shape.drawShape();
                DrawPicture.INSTANCE.drawByBufferedImage(picture,i+""+j);
            }
        }


    }
}
